package asapi

import (
	"jgt-sdk/utils"
)

var gAPIHandle *APIHandle

// InitAPI 初始化API接口调用
func InitAPI(cfg *Config) *APIHandle {
	gAPIHandle = NewAPIHandle(cfg)
	return gAPIHandle
}

// GetAPI 获取API
func GetAPI() *APIHandle {
	return GetAPIWithTraceID("")
}

// GetAPIWithTraceID 获取API
func GetAPIWithTraceID(traceID string) *APIHandle {
	if gAPIHandle == nil {
		panic("未初始化API")
	}

	if traceID == "" {
		traceID = utils.UUIDString()
	}

	handle := *gAPIHandle
	handle.traceID = traceID
	return &handle
}
